﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WilsonWebsite
{
    public partial class ProDetail : System.Web.UI.Page
    {
        protected Model.Product pro = new Model.Product();
        protected string catNameStr = string.Empty;
        private string strCon = Global.strCon;
        protected int proId = 0;
        protected string initMediumImg = string.Empty;
        protected string initBigImg = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                proId = Convert.ToInt32(Request["proId"]);  //商品id
                GetProInfo(strCon, proId);  //商品信息
                BindOtherImg(strCon, "proId=" + proId);  //商品其他信息
                GetCatInfoByCatId(strCon, pro.CatId);  //浏览路径
            }
        }

        #region 商品信息
        protected void GetProInfo(string strCon,int proId)
        {
            using (DataTable dtpi = Bll.Product.Single(strCon, proId))
            {
                if (dtpi != null && dtpi.Rows.Count > 0)
                {
                    pro.ProName = dtpi.Rows[0]["ProName"].ToString();
                    pro.ProTypeNum = dtpi.Rows[0]["ProTypeNum"].ToString();
                    pro.Summary = dtpi.Rows[0]["Summary"].ToString();
                    pro.Description = dtpi.Rows[0]["Description"].ToString();
                    pro.ProContent = dtpi.Rows[0]["ProContent"].ToString();
                    pro.PackInfo = dtpi.Rows[0]["PackInfo"].ToString();
                    pro.BigImgURL = dtpi.Rows[0]["BigImgURL"].ToString();
                    pro.MediumImgURL = dtpi.Rows[0]["MediumImgURL"].ToString();
                    pro.CatId = Convert.ToInt32(dtpi.Rows[0]["CatId"]);
                }
            }
        }

        protected void BindOtherImg(string strCon,string whereStr) 
        {
            using (DataTable dtoi = Bll.ProOtherInfo.Single(strCon, whereStr))
            {
                if (dtoi != null && dtoi.Rows.Count > 0)
                {
                    initMediumImg = dtoi.Rows[0]["OtherMediumImgURL"].ToString();
                    initBigImg = dtoi.Rows[0]["OtherBigImgURL"].ToString();
                    repOtherImg.DataSource = dtoi.DefaultView;
                    repOtherImg.DataBind();
                }
            }
        }
        #endregion

        #region 浏览路径
        protected void GetCatInfoByCatId(string strCon, int catId)
        {
            using (DataTable dtci = Bll.Category.Single(strCon, catId))
            {
                if (dtci != null && dtci.Rows.Count > 0)
                {
                    catNameStr = dtci.Rows[0]["CatName"].ToString();
                }
            }
        }
        #endregion
    }
}
